/*
 * ChatUserInfoManager.java
 *
 * Created on 2007年5月17日, 上午10:43
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.pphome.orgmodel.manager;

import com.ecomm.platcore.service.BaseEntityManager;
import com.ecomm.util.DB;
import com.ecomm.util.DBFactory;
import com.ecomm.util.HibernateUtil;
import com.ecomm.util.SpringUtil;
import com.pphome.orgmodel.pojo.OrgInfo;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Session;


/**
 *
 * <p>Title: 易讯聊天系统</p>
 * <p>Description:
 *  易讯聊天系统
 * </p>
 * <p>Copyright: Copyright (c) 2007</p>
 * <p>Company: 联合易讯 </p>
 * @author <font color='blue'>pijunliang</font> &nbsp&nbsp<a href="mailto:pijunliang@hotmail.com">pijunliang@hotmail.com</a>
 * @version 1.0
 * @since 2007年5月17日, 上午10:43
 */
public class OrgManager extends BaseEntityManager<OrgInfo> {
    
    /** Creates a new instance of ChatRemindManager */
    public OrgManager() {
        
    }
    private static OrgManager orgManager = null;
    
    public static OrgManager getInstance(){
        if(orgManager == null){
            orgManager = (OrgManager)SpringUtil.getBean("orgManager");
        }
        return orgManager;
    }
    public String doSaveDefaultOrg(){
        OrgInfo oi = new OrgInfo();
        oi.setChildren("0");
        oi.setName("自由人");
        oi.setParentid("");
        return  this.doSaveEntity(oi);
        
    }
    /**
     * 保存业务对象的函数.
     */
    public String doSaveEntity(OrgInfo object) {
        return (String) getHibernateTemplate().save(object);
    }
    public void doUpdateEntity(OrgInfo object) {
        this.getHibernateTemplate().update(object);
    }
    public List getOrgListByParentid(String parentid){
        String hql = "from OrgInfo where 1=1 ";
        if(parentid != null && !parentid.equals("")){
            hql += " and parentid = '"+parentid+"'";
        }else{
            hql += " and parentid is null ";
        }
        return this.getHibernateTemplate().find(hql);
    }
    public OrgInfo getOrgInfoById(String id){
        if(id == null || id.equals("")){
            return null;
        }
        return (OrgInfo)this.find("from OrgInfo where id = '"+id+"'");
    }
    public OrgInfo getOrgInfoByName(String name){
        if(name == null || name.equals("")){
            return null;
        }
        return (OrgInfo)this.find("from OrgInfo where name = '"+name+"'");
    }
    /**
     *覆盖父类的方法
     */
    public  Object find(String hql){
        List list =  this.getHibernateTemplate().find(hql);
        if(list != null && list.size() >0 ){
            return list.get(0);
        }else{
            return null;
        }
    }
}
